package com.kehutong.crm.entity;

import java.util.ArrayList;
import java.util.List;

import com.kehutong.crm.enums.TagSourceType;
import com.kehutong.crm.enums.ThirdPartySource;
import org.coraframework.bean.valid.CheckField;
import org.coraframework.orm.Entity;
import org.coraframework.orm.annotation.Column;
import org.coraframework.orm.annotation.Table;
import org.coraframework.orm.annotation.UnSave;

import com.kehutong.common.entity.ITree;

/**
 * 第三方标签
 *
 * @Author: liuzhen (liuxing521a@163.com)
 * @Date: 20/4/13 上午9:08
 */
@Table(value="t_tag", comment="用户标签,目前分两级,第一级微类别；第二级级标签", multi=true)
public class Tag extends Entity implements ITree<Tag> {

	private static final long serialVersionUID = 4177501639936105917L;

	protected Tag(String id) {
        super(id);
    }

    @CheckField("上级标签不能为空")
    @Column(length = 64, comment = "上级标签")
    private String pid;

    @UnSave
    private String pname;

    @CheckField("标签名称不能为空")
	@Column(comment = "标签名称")
    private String  name;

    @Column(comment="标签来源类型")
    private TagSourceType type;

    @Column(comment = "标签描述")
    private String desc;
	
	@Column(comment = "是否标签组")
	private boolean group;

    @Column(comment = "第三方标签来源")
    private ThirdPartySource thirdPartySource;

    @Column(comment = "状态：0禁用，1启用")
    private boolean status;

    @Column(comment = "排序")
    private long sort;

    @Column(comment = "使用数量")
    private long useCount;

    @Column(comment = "逻辑删除")
    private boolean deleted;

    @Column(comment="操作人")
    private String createBy;

    @Column(comment = "操作人名字")
    private String createName;

    @UnSave private List<Tag> childList;

    @UnSave private String companyNo;

    public boolean isGroup() {
		return group;
	}

	public void setGroup(boolean group) {
		this.group = group;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public List<Tag> getChildList() {
        return childList;
    }

    public void setChildList(List<Tag> childList) {
        this.childList = childList;
    }
    
    public void addChild(Tag tag) {
		if (childList == null) {
			childList = new ArrayList<>();
		}
		childList.add(tag);
	}


	@Override
	public String getPid() {
		return pid;
	}

    @Override
    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        Tag templateTag = (Tag) o;

        if (group != templateTag.group) return false;
        if (!pid.equals(templateTag.pid)) return false;
        return name.equals(templateTag.name);
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + pid.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + (group ? 1 : 0);
        return result;
    }

    
    public String getPname() {
        return pname;
    }

    public void setPname(String pname) {
        this.pname = pname;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public String getCreateName() {
        return createName;
    }

    public void setCreateName(String createName) {
        this.createName = createName;
    }

    public ThirdPartySource getThirdPartySource() {
        return thirdPartySource;
    }

    public void setThirdPartySource(ThirdPartySource thirdPartySource) {
        this.thirdPartySource = thirdPartySource;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public TagSourceType getType() {
        return type;
    }

    public void setType(TagSourceType type) {
        this.type = type;
    }

    public long getSort() {
        return sort;
    }

    public void setSort(long sort) {
        this.sort = sort;
    }

    public long getUseCount() {
        return useCount;
    }

    public void setUseCount(long useCount) {
        this.useCount = useCount;
    }

    public String getCompanyNo() {
        return companyNo;
    }

    public void setCompanyNo(String companyNo) {
        this.companyNo = companyNo;
    }
}